﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SimpleRcon.Windows
{
    /// <summary>
    /// Interaction logic for ManageBookmarksWindow.xaml
    /// </summary>
    public partial class ManageBookmarksWindow : Window
    {
        public ManageBookmarksWindow()
        {
            InitializeComponent();

            // Load
            LoadBookmarks();
        }

        private void LoadBookmarks()
        {
            // Just throw the items in, as we are using the Bookmarks class ToString, to generate the text
            listbox_view.ItemsSource = BookmarkCollection.Items;
        }

        private void button_Add_Click(object sender, RoutedEventArgs e)
        {
            // Create
            Bookmark mark = new Bookmark();
            mark.Name = textbox_Name.Text;
            mark.Address = textbox_Address.Text;
            mark.Password = textbox_Password.Text;

            // Save
            BookmarkCollection.AddItem(mark);

            // Clear
            textbox_Address.Text = string.Empty;
            textbox_Name.Text = string.Empty;
            textbox_Password.Text = string.Empty;

            // Reload
            LoadBookmarks();

            // Return focus to textbox_Name
            textbox_Name.Focus();
        }

        private void button_Delete_Click(object sender, RoutedEventArgs e)
        {
            if (listbox_view.SelectedItem != null)
            {
                // Delete and reload
                BookmarkCollection.RemoveItem((Bookmark)listbox_view.SelectedItem);
                LoadBookmarks();
            }
        }
    }
}
